package com.iseastar.guojiang.wallet;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.iseastar.guojiang.model.WalletMoneyRecordBean;
import com.shouhuobao.station.R;

import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterExt;
import droid.frame.utils.sqlite.DateUtils;


/**
 * 资金记录适配器
 * Created by lidandan on 2018/1/17.
 */
public class WalletMoneyRecordAdapter extends BaseAdapterExt<WalletMoneyRecordBean> {

    public WalletMoneyRecordAdapter(ArrayList<WalletMoneyRecordBean> items, Activity context) {
        super(items, context);
        setEmptyView(R.layout.wallet_money_record_empty);

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (hasEmptyView()) {
            return super.getView(position, convertView, parent);
        }
        ViewHolder holder;
        if (convertView == null || convertView.getTag() == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.wallet_money_record_item, parent, false);
            holder = new ViewHolder();
            holder.withDrawCode = (TextView) convertView.findViewById(R.id.with_draw_code_tv);
            holder.timeTV = (TextView) convertView.findViewById(R.id.time_tv);
            holder.montyRecordTV = (TextView) convertView.findViewById(R.id.monty_record_tv);
            holder.brokerageTV = (TextView) convertView.findViewById(R.id.brokerage_tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        WalletMoneyRecordBean item = items.get(position);
        holder.timeTV.setText(DateUtils.format(item.getCreateTime()));
        if (item.getType() == 1) {
            if (item.getAccountType() == 3) {
                holder.withDrawCode.setVisibility(View.GONE);
                holder.brokerageTV.setText("每日首单奖励");
                holder.montyRecordTV.setText("+" + item.getMoney());
            } else {
                holder.withDrawCode.setVisibility(View.VISIBLE);
                holder.brokerageTV.setText("佣金收入");
                holder.withDrawCode.setText("任务编号：" + item.getTaskNo());
                holder.montyRecordTV.setText("+" + item.getMoney());
            }
        } else if (item.getType() == 2) {
            holder.withDrawCode.setVisibility(View.GONE);
            holder.brokerageTV.setText("提现");
            holder.montyRecordTV.setText("-" + item.getMoney());
        } else if (item.getType() == 3) {
            holder.withDrawCode.setVisibility(View.VISIBLE);
            holder.brokerageTV.setText("信息费");
            holder.withDrawCode.setText("任务编号：" + item.getTaskNo());
            holder.montyRecordTV.setText("-" + item.getMoney());
        }
        return convertView;
    }

    class ViewHolder {
        private TextView withDrawCode;
        private TextView timeTV;
        private TextView montyRecordTV;
        private TextView brokerageTV;
    }
}
